//
//  WWWeatherAPI.m
//  WhatWeather
//
//  Created by byn on 15/10/11.
//  Copyright © 2015年 byn. All rights reserved.
//

#import "WWWeatherAPI.h"
#import "WWCommonUtility.h"

@implementation WWWeatherAPI

+ (AFHTTPRequestOperationManager *)networkManager{
    static AFHTTPRequestOperationManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [AFHTTPRequestOperationManager manager];
    });
    return manager;
}
/**
 *   请求天气接口
 *
 *  @param areaID   城市ID
 *  @param sucBlock 成功返回数据后回调
 */
-(void) ReqForNormalWeather:(NSString *)areaID sucBlock:(sucBlock)sucBlock {
    
    //url
    NSString *url = [NSString stringWithFormat:@"https://api.heweather.com/x3/weather?cityid=%@&key=91823b49723e4a9398425768c295e8d4", areaID];
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    //request
    [WWWeatherAPI networkManager].responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/plain", @"text/json", @"text/javascript", nil];
    [[WWWeatherAPI networkManager] GET:url parameters:nil
              success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
                  
                  NSLog(@"Json: %@",operation.responseString);
                  sucBlock(responseObject,operation.responseString);
    }
              failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
                  
                  NSLog(@"Error: %@",error);
    }];
}
@end











































